package seentao.stdev.mobile.util;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.springframework.core.io.Resource;

import lombok.Cleanup;
import lombok.SneakyThrows;

public class IOUtil {

	@SneakyThrows
	public static String getText(Resource res) {
		@Cleanup InputStream is = res.getInputStream();
		return getText(is);
	}

	@SneakyThrows
	public static String getText(InputStream is) {
		@Cleanup BufferedReader reader = new BufferedReader(new InputStreamReader(is));
		StringBuilder sb = new StringBuilder();
		for(String line=null; (line=reader.readLine()) != null;) {
			 sb.append(line + "\r\n");
		}
		return sb.toString();
	}

}
